package com.swgk.core.view.selection;

import android.util.SparseArray;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Created by WYJ on 2020-12-02.
 */
public class CopyUtils {

    public static SparseArray<XChooseEntity> deepPopEntityCopy(SparseArray<XChooseEntity> src) {
        SparseArray<XChooseEntity> dest = new SparseArray<>();
        XChooseEntity newEntity;
        for (int i = 0; i < src.size(); i++) {
            int key = src.keyAt(i);
            XChooseEntity entity = src.get(key);
            newEntity = new XChooseEntity(entity.getSort(), entity.getTypeName(), entity.getList());
            newEntity.setHide(entity.isHide());
            dest.put(key, newEntity);
        }
        return dest;
    }

    public static Map<String, List<CommonPopEntity>> memberTypeToJson(List<CommonPopEntity> data) {
        Map<String, List<CommonPopEntity>> map = new HashMap<>();
        map.put("firstCategory", new ArrayList<>());
        map.put("secondCategory", new ArrayList<>());
        map.put("thirdCategory", new ArrayList<>());
        map.put("fourCategory", new ArrayList<>());
        map.put("fiveCategory", new ArrayList<>());
        map.put("sixCategory", new ArrayList<>());
        if (data == null || data.size() == 0) {
            return map;
        }
        for (int i = 0; i < data.size(); i++) {
            CommonPopEntity popEntity = data.get(i);
            int key = Integer.parseInt(popEntity.getId());
            CommonPopEntity tempEntity = new CommonPopEntity(popEntity.getNo(), popEntity.getTypeName());
            switch (key) {
                case 0:
                    Objects.requireNonNull(map.get("firstCategory")).add(tempEntity);
                    break;
                case 1:
                    Objects.requireNonNull(map.get("secondCategory")).add(tempEntity);
                    break;
                case 2:
                    Objects.requireNonNull(map.get("thirdCategory")).add(tempEntity);
                    break;
                case 3:
                    Objects.requireNonNull(map.get("fourCategory")).add(tempEntity);
                    break;
                case 4:
                    Objects.requireNonNull(map.get("fiveCategory")).add(tempEntity);
                    break;
                case 5:
                    Objects.requireNonNull(map.get("sixCategory")).add(tempEntity);
                    break;
            }
        }
        return map;
    }


    /**
     * 三级标题，通过category不同显示的不同
     *  TYPE_3(3, "商品&材料"),
     *         TYPE_4(4, "专业工程"),
     *         TYPE_2(2, "劳务分包"),
     *         TYPE_10(10, "工程总包"),
     *         TYPE_13(13, "PPP项目"),
     *         TYPE_1(1, "机械租赁"),
     *         TYPE_5(5, "设备租赁"),
     *         TYPE_14(14, "土地产权转让"),
     *         TYPE_15(15, "房产转让"),
     *         TYPE_7(7, "设计规划"),
     *         TYPE_8(8, "专业监理"),
     *         TYPE_6(6, "地质勘察"),
     *         TYPE_9(9, "造价咨询"),
     *         TYPE_11(11, "房产租赁"),
     *         TYPE_12(12, "车辆租赁"),
     *         TYPE_16(16, "机械转让"),
     *         TYPE_17(17, "设备转让"),
     *         TYPE_18(18, "车辆转让"),
     *         TYPE_19(19, "物流货运"),
     *         TYPE_20(20, "其他");
     */
    private static final String[][] titles = new String[][]{
            new String[]{"机械分类", "机械类型"},
            new String[]{"工程类别", "专业分类", "业务类别"},
            new String[]{"商品分类", "商品类别", "商品品名"},
            new String[]{"工程类别", "专业分类", "业务类型"},
            new String[]{"设备分类", "设备类型"},
            new String[]{"房产类型", "房产分类"},
            new String[]{"货物类型", "要求车型"},
    };

    public static String[] getCateTitle(int pos, int category) {
        String name1 = "";
        String name2 = "";
        String name3 = "";
        if(pos > 0){
            if (category == 6 || category == 7 || category == 8 || category == 9 || category == 10) {
                name1 = titles[3][0];
                name2 = titles[3][1];
                name3 = titles[3][2];
            } else if (category == 11 || category == 15) {
                name1 = "房产类型";
            } else if (category == 12 || category == 18) {
                name1 = "车型";
            } else if (category == 13) {
                name1 = "工程类别";
            } else if (category == 14) {
                name1 = "土地用途";
            } else if (category == 16) {
                name1 = titles[0][0];
                name2 = titles[0][1];
            } else if (category == 17) {
                name1 = titles[4][0];
                name2 = titles[4][1];
            } else if (category == 19) {
                name1 = titles[6][0];
                name2 = titles[6][1];
            } else {
                if (category > 0 && category != 20) {
                    name1 = titles[category - 1][0];
                    name2 = titles[category - 1][1];
                    if (titles[category - 1].length == 3) {
                        name3 = titles[category - 1][2];
                    }
                }
            }
        }
        return new String[]{name1, name2, name3};
    }

}
